-- Copyright (c) 2025 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local class = require 'mc.class'
local measurement = require 'domain.measurement'

local component_integrity = class()

function component_integrity:ctor(id, chassis_id, mdb_name, integrity_info, measurement_info)
    -- 此处需要将C++返回回来的table转换为lua_table
    local integrity = {
        ['type'] = integrity_info.type,
        ['version'] = integrity_info.version,
        ['last_updated'] = integrity_info.lastUpdated
    }
    local measurement_set_info = {
        ['specification'] = measurement_info.specification,
        ['summary_type'] = measurement_info.summaryType,
        ['hash_algo'] = measurement_info.summaryHashAlgorithm,
        ['hash'] = measurement_info.summaryHash,
        ['measurements_count'] = measurement_info.measurementsCount
    }

    self.m_id = id
    self.m_chassis_id = chassis_id
    self.m_mdb_name = mdb_name
    self.m_integrity_info = integrity
    self.m_measurement_info = measurement_set_info
    self.m_measurement_set = {}
end

function component_integrity:init()

end

function component_integrity:add_measurement(meas)
    if self.m_measurement_set[meas.index] then
        self.m_measurement_set[meas.index] = nil
    end
    self.m_measurement_set[meas.index] = measurement.new(self.m_chassis_id, self.m_mdb_name, meas)
end

return component_integrity